package com.zqwh.storemonitor;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;

import com.igexin.sdk.IUserLoggerInterface;
import com.videogo.openapi.EZOpenSDK;
import com.zqwh.storemonitor.domain.Camera;
import com.zqwh.storemonitor.domain.Shop;
import com.zqwh.storemonitor.domain.ShopWatcher;
import com.zqwh.yj.sdk.utils.LogUtils;

public class StoreMonitorApplication extends Application {
    public static Context sContext;
    public static ShopWatcher sShopWatcher;
    public static Shop sSelectedShop;
    public static Camera sSelectedCamera;
    public static String sGeTuiCid;

    public static EZOpenSDK getOpenSDK(){
        return EZOpenSDK.getInstance();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        sContext = this;
        com.igexin.sdk.PushManager.getInstance().initialize(this);
        com.igexin.sdk.PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() {
            @Override
            public void log(String s) {
                LogUtils.logout("PUSH_LOG : "+s);
            }
        });
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) {
                throwable.printStackTrace();
                // 抓取到异常时，立即重启应用
                restartApp(StoreMonitorApplication.this);
            }
        });
    }

    public static void restartApp(Context context){
        final Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        if (intent != null){
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            context.startActivity(intent);
            System.exit(0);
        }
    }
}
